(function () {
    //获取屏幕宽高
    function getScreen() {
        let width, height;
        if (window.innerWidth) {//IE9及以上
            width = window.innerWidth;
            height = window.innerHeight;
        } else if (document.compatMode === "BackCompat") {//混杂模式
            width = document.body.clientWidth;
            height = document.body.clientHeight;
        } else {
            width = document.documentElement.clientWidth;
            height = document.documentElement.clientHeight;
        }
        return {
            width:width,
            height:height
        }
    }

    // 防抖函数
    function debounce(fn, delay) {
        let timeId = null;
        return function() {
            let self = this;
            let args = arguments;
            timeId && clearTimeout(timeId);
            timeId =  setTimeout(function() {
            // console.log("发送网络请求");
            fn.apply(self,args);
        }, delay || 1000);
        }
    }

    // 函数节流 throttle
    function throttle(fn, delay) {
        let timeId = null;
        let flag = true;
        return function() {
            if (!flag) return;
            flag = false;
            let self = this;
            let args = arguments;
            timeId && clearTimeout(timeId);
            timeId =  setTimeout(function() {
            flag = true;
            fn.apply(self,args);
        }, delay || 1000);
        }
    }
    window.getScreen = getScreen;
    window.debounce = debounce;
    window.throttle = throttle;
})();